package com.xupypr.surgery.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.RootPanel;

public class AdminPanel implements EntryPoint {

	private final IAdminPanelDispatcherAsync dispatcher = GWT
			.create(IAdminPanelDispatcher.class);

	private final DeckPanel panel  = new DeckPanel();
	
	private EditorWidget editor;
	private EntriesListWidget entriesList;

	public void onModuleLoad() {
		RootPanel.get("adminPanel2").add(new HTMLPanel("OMGQQQ!!1!"));
		RootPanel.get("adminPanel").add(panel);
		panel.setSize("100%","100%");
		
		editor = new EditorWidget(this);	
		editor.setSize("100%", "100%");
		panel.add(editor);

		entriesList = new EntriesListWidget(this);		
		entriesList.setSize("100%", "100%");
		panel.add(entriesList);	
		
		panel.showWidget(1);
	}
	
	public void switchMode() {
		panel.showWidget(1 - panel.getVisibleWidget());
	}
	
	public IAdminPanelDispatcherAsync getDispatcher() {
		return dispatcher;
	}

	public void loadEntryToEditor(Long id) {		
		editor.loadEntry(id);
	}

	public void refreshEntriesList(Long editedEntryId) {
		entriesList.refresh();
	}
}
